package net.ibizsys.eclipse.studio.console;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

/**
 * 
 * @author <a href='http://www.weibo.com/xjtoo' target='_blank'>Enmaai</a>
 */
public class Console
{
	private static final String DEFAULT_CONSOLE_NAME = "IBiz5 Studio";

	public static void println(String message)
	{
		println(1, message);
	}

	public static void println(int level, String message)
	{
		message += "\n";

		MessageConsole console = null;

		IConsoleManager iConsoleManager = ConsolePlugin.getDefault().getConsoleManager();

		IConsole[] consoles = iConsoleManager.getConsoles();
		if (consoles.length > 0)
		{
			console = (MessageConsole) consoles[0];
		} else
		{
			console = new MessageConsole(DEFAULT_CONSOLE_NAME, null);
			iConsoleManager.addConsoles(new IConsole[] { console });
		}
		iConsoleManager.showConsoleView(console);
		MessageConsoleStream consoleStream = console.newMessageStream();

		consoleStream.print(message);
	}
}
